﻿@page "/card"

@using NorthwindBlazor.Data
@using NorthwindBlazor.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext

<RadzenExample Name="Card">
<RadzenCard Style="width:600px; margin-bottom: 20px; height:500px;">
    <div class="row">
        <div class="col-md-6">
            <div>Company:</div>
            <b>@lastOrder.Customer?.CompanyName</b>
            <div style="margin-top:20px">Employee:</div>
            <b>@(lastOrder.Employee?.FirstName + " " + lastOrder.Employee?.LastName)</b>
            <br />
            <RadzenImage Path="@lastOrder.Employee?.Photo" Style="width:100px;" />
        </div>
        <div class="col-md-6">
            <div>Freight:</div>
            <b>@String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", lastOrder.Freight)</b>
            <div style="margin-top:20px">Ship country:</div>
            <b>@(lastOrder.ShipCountry)</b>
            <div style="margin-top:20px">Ship city:</div>
            <b>@(lastOrder.ShipCity)</b>
            <div style="margin-top:20px">Ship name:</div>
            <b>@(lastOrder.ShipName)</b>
        </div>
    </div>
</RadzenCard>
</RadzenExample>

@code {
    IEnumerable<Order> orders;
    Order lastOrder;

    protected override async Task OnInitializedAsync()
    {
        var query = (from order in dbContext.Orders
                            .Include("Customer")
                            .Include("Employee")
                            .Include("OrderDetails")
                            .Include("OrderDetails.Product")
                    select order).ToList();

        lastOrder = query.Last();

        orders = await Task.FromResult(query);
    }
}
